package kitty.main;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Projectile {
	private float x, y, speed;
	private boolean remove;
	private int row, damage, type;
	private Bitmap image;
	private MainView view;
	private Kitty kitty;
	private ArrayList<Enemy> enemies;

	public Projectile(MainView view, Kitty kitty) {
		this.kitty = kitty;
		this.row = kitty.getRow();
		this.view = view;
		this.image = kitty.getProjectileImage();
		this.x = kitty.getX() + 50;
		this.y = kitty.getY() + 30;
		enemies = view.getEnemies();
		speed = 300.0f;
		damage = kitty.getDamage();
	}

	public void render(Canvas canvas) {
		canvas.drawBitmap(image, x, y, null);

		update();
	}

	public void update() {
			x += speed * view.getDelta();

			checkCollission();
	}

	public boolean getRemoved() {
		return remove;
	}

	public void doSomething(int i) {
		view.playHitSound();
		if (kitty.getType() == 0) {
			enemies.get(i).damage(damage);
		}
		
		else if(kitty.getType() == 3){
			enemies.get(i).slowdown();
		}
	}

	private void checkCollission() {
		for (int i = 0; i < enemies.size(); i++) {
			if (x > enemies.get(i).getX()
					&& x < x + enemies.get(i).getEnemyImages()[0].getWidth()) {
				if (!enemies.get(i).isDead() && row == enemies.get(i).getId()) {
					doSomething(i);
					remove = true;
					break;
				}
			}
		}
	}
}